Skip to content

8295851: Do not use ttyLock in BytecodeTracer::trace #25915

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

coleenp
Copy link
Contributor

@coleenp coleenp commented Jun 20, 2025

This didn't need ttyLock for synchronization, the code only needs to see if the method changes so it can print the method name before the bytecodes, like:

[490166] static void java.lang.String.()
[490166] 13 18 putstatic 613 <java/lang/String.CASE_INSENSITIVE_ORDER:Ljava/util/Comparator;>
[490166] 14 21 return

[490166] static void java.lang.System.()
[490166] 15 0 invokestatic 471 <java/lang/System.registerNatives()V>
[490166] 16 3 aconst_null
[490166] 17 4 putstatic 474 <java/lang/System.in:Ljava/io/InputStream;>

Verified manually and added some parallelism to the test, and fixed trace() to initialize is_linked(), which it always is.
Also ran tier1-4.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8295851: Do not use ttyLock in BytecodeTracer::trace (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25915/head:pull/25915
$ git checkout pull/25915

Update a local copy of the PR:
$ git checkout pull/25915
$ git pull https://git.openjdk.org/jdk.git pull/25915/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 25915

View PR using the GUI difftool:
$ git pr show -t 25915

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25915.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 20, 2025

👋 Welcome back coleenp! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Jun 20, 2025

@coleenp This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8295851: Do not use ttyLock in BytecodeTracer::trace

Reviewed-by: dholmes

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 81 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 20, 2025
@openjdk
Copy link

openjdk bot commented Jun 20, 2025

@coleenp The following label will be automatically applied to this pull request:

  • hotspot-runtime

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@mlbridge
Copy link

mlbridge bot commented Jun 20, 2025

Webrevs

Comment on lines 179 to 182
// We need a global instance to keep track of the method being printed so we can report that
// the method has changed. If this method is redefined and removed, that's ok because the method passed in won't match, and
// this will print that one.
static Method* _current_method = nullptr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if we are calling trace_interpreter from multiple threads they will each stomp on this shared global field. Sorry I can't see how some form of locking is not needed here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If multiple threads change the value of _current_method, the method printing will print the method name again. That's a benign race.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So actually this wasn't more racy than what was there in this respect. You could change the global method before taking the ttyLock and for multiple threads, this would claim that the current method had changed. The old code also had shared state for BytecodeTracer. Now this uses a local instance, which can then print the bytecode at the given location.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the old code (mis)used a shared ByteCodeTracer instance, and the new code gives each use a local ByteCodeTracer but seeds it from the global shared field. So I agree the level of raciness seems unchanged.

But printing an unrelated method name still seems a bad thing to do. ??

BTW it is also very confusing to give the global variable the same name as the private field in ByteCodeTracer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would print the right name it would just print it again. Say:
t1 printing M1 so prints the name
t1 aload
t1 astore
t2 printing M2 method name
t2 getfield
t1 < continues printing M1 but method name was changed to M2> prints M1 method name
t1 invokevirtual
...

The thread id is printed before each line. Using this with multiple threads is not ideal for getting information clearly but that's not what people do.

// There used to be a leaf mutex here, but the ttyLocker will
// work just as well, as long as the printing operations never block.
_interpreter_printer.trace(method, bcp, tos, tos2, st);
BytecodePrinter printer(_current_method);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need a Atomic::load_acquire here to pair with the Atomic::release_store below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, added and changed the name of current_method, and added comments. Hope it helps.

Copy link
Member

@dholmes-ora dholmes-ora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I finally realized the strange way in which this code works.

You could use a ThreadLocal for the current method being printed.

But I'm okay with the current changes.

Thanks

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 25, 2025
@coleenp
Copy link
Contributor Author

coleenp commented Jun 25, 2025

You could use a ThreadLocal for the current method being printed.

Oh yes that would be better, but I hate to add things to Thread for just one use. Actually, reprinting the method name probably helps with readability if multiple threads are interleaving output.

Thanks for the review @dholmes-ora

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-runtime [email protected] ready Pull request is ready to be integrated rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

2 participants